home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 June: Reference Library / Dev.CD Jun 00 RL Disk 1.toast / pc / technical documentation / develop / develop issue 24 / develop issue 24 code / scriptable database 1.0a15.sea / Scriptable Database 1.0a15 / Base / Exceptions.cp / Exceptions.cp
Encoding:
Text File  |  1996-02-20  |  4.9 KB  |  178 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Exceptions.c
  3.  
  4.     Contains:    exception handling stuff
  5.  
  6.     Written by:    Bruce Horn, Steve Capps, Larry Kenyon, John Meier, scott douglass, Darin Adler,
  7.                 Paul Mercer, Bryan Stearns, Dave Owens
  8.                 
  9.                 Andy Nicholas
  10.  
  11.     Copyright:    © 1988-1995 by Apple Computer, Inc., all rights reserved.
  12.  
  13.          <2>     2/24/95    ga        
  14. */
  15.  
  16. #if 0
  17.  
  18. #ifdef MWTRACEBACKTABLES
  19. #pragma traceback on
  20. #endif
  21.  
  22. #include "Exceptions.h"
  23. #include "Debug.h"
  24.  
  25. //
  26. // For SysError
  27. //
  28. #include <Errors.h>
  29.  
  30. #ifdef METROWERKSPOWERPC
  31. extern DestructorChain* __local_destructor_chain;
  32. extern "C" void __destroy_local_objects_to(DestructorChain *lastregmem);
  33. #endif
  34.  
  35. //
  36. // Globals for the exception handler
  37. //
  38. TException* gExceptionStack;
  39. SInt32        gExceptionMessage;
  40. SInt32        gExceptionError;
  41.  
  42. #pragma segment Resident
  43. //----------------------------------------------------------------------------------------
  44. // TException::TException: 
  45. //----------------------------------------------------------------------------------------
  46. TException::TException()
  47.     {
  48.     fPrevious             = gExceptionStack;
  49.     gExceptionStack     = this;
  50.     fFired                 = false;
  51.  
  52.     //
  53.     // Since we're just constructing the TException, we don't have any exception actions
  54.     //
  55.     fExceptionAction                = nil;
  56.  
  57.     //
  58.     // Save the A5 world
  59.     //
  60. #ifdef SIXTYEIGHTK
  61.     fA5                 = GetA5();
  62. #endif
  63.  
  64. #ifdef METROWERKSPOWERPC
  65.     //
  66.     // Save the current local destructor chain so when we fail we can destroy all objects
  67.     // allocated on the stack past this point.
  68.     //
  69.     fLocalDestructorChain = __local_destructor_chain;
  70. #endif
  71.     }
  72.  
  73.  
  74. //----------------------------------------------------------------------------------------
  75. // TException::~TException: 
  76. //
  77. // If we caught an exception we will already be off the stack
  78. //----------------------------------------------------------------------------------------
  79. TException::~TException()
  80.     {
  81.     if (fFired == false)
  82.         {
  83.         if (gExceptionStack != this)
  84.             {
  85.             ASSERTPRINT(false, ("PopExceptionHandler - Stack nesting error"));
  86.             SysError(dsLoadErr);
  87.             }
  88.             
  89.         gExceptionStack = fPrevious;
  90.         }    
  91.     }
  92.     
  93.                 
  94. //----------------------------------------------------------------------------------------
  95. // Fail: 
  96. //----------------------------------------------------------------------------------------
  97. void Fail(SInt32 error, SInt32 message)
  98.     {
  99. //    ASSERTPRINT(!gDebugGlobals->dbgExceptionBreaking, ("Fail(%d, %d)", error, message));
  100.  
  101.     gExceptionError     = error;
  102.     gExceptionMessage     = message;
  103.     
  104.     FailAgain();
  105.     }
  106.  
  107.  
  108. //----------------------------------------------------------------------------------------
  109. // FailAgain:
  110. //----------------------------------------------------------------------------------------
  111. void FailAgain()
  112.     {
  113.     TException* exception = gExceptionStack;
  114.  
  115.     if (exception == nil)
  116.         {
  117.         ASSERTPRINT(false, ("FAIL() with no handlers!"));
  118.         SysError(dsLoadErr);
  119.         }
  120.  
  121.     exception->fFired = true;
  122.     gExceptionStack = exception->fPrevious;
  123.     
  124. #ifdef METROWERKSPOWERPC
  125.     //
  126.     // Destroy any objects allocated on the stack since we began this exception block.
  127.     // We have to do this because otherwise local objects get destroyed at some undefined
  128.     // later point and often they’ve been overwritten by subsequent stack allocations!
  129.     //
  130.     __destroy_local_objects_to(exception->fLocalDestructorChain);
  131. #else
  132.     //
  133.     // Most compilers (CFront and xlC, anyway) do not support destruction of local objects
  134.     // after a longjmp.  The only destructors we really care about are TLoops since that’s
  135.     // where the TList gets unlocked.  To prevent the list from being locked forever, we
  136.     // make sure that any loops that were allocated within the current exception frame are
  137.     // cleaned up properly.
  138.     //
  139.     TExceptionAction* exceptionAction = exception->RemoveExceptionAction();
  140.     while(exceptionAction != nil)
  141.         {
  142.         exceptionAction->CatchException();
  143.         exceptionAction = exception->RemoveExceptionAction();
  144.         }
  145. #endif
  146.  
  147.     //
  148.     // Last, restore the 68K a5
  149.     //
  150. #ifdef SIXTYEIGHTK
  151.     SetA5(exception->fA5);
  152. #endif
  153.  
  154.     longjmp(exception->fEnv, 0);    
  155.     }
  156.  
  157.  
  158. /*
  159.     August 18, 1993, 7:06pm, Cupertino, CA.
  160.     
  161.     It was going to be a wild, delirious night, free of clouds and antelopes, but the sun had not yet set, and
  162.     the air was still full of the summer California belief.  But later this evening, Mike knew that all would 
  163.     be different, and those that smiled in the direction of the ocean would wonder why they dreamed the sequence
  164.     of yesterday's lunch.  Tonight, Mike knew, was the beginning of a new circular metaphor of forested valleys.
  165.     
  166.     But wait!  How could I babble all this?  Who am I to declare the meaning of today's final yawn of sky?
  167.     Humble me greatly, before I declare to understand the world, let alone myself.
  168.     
  169.     As I wander through the forest of my own distainful glance toward the South, I trip and fall, landing on 
  170.     the ice cream cone of a child that had already grown.  This, I declare is my fate, and I will live it and 
  171.     believe it with all my might.
  172.     
  173.     - an anonymous Clam Seeking Apple Engineer, wandering, ever wandering.
  174.       (I really should not leave Mike Lockwood near my machine with files checked out -andy)
  175. */
  176.  
  177. #endif
  178.